package cn.edu.lingnan.servlet.student;

import cn.edu.lingnan.pojo.Student;
import cn.edu.lingnan.service.StudentService;
import cn.edu.lingnan.service.StudentServiceMysqlImpl;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/admin/student/updateStu")
public class UpdateStudentServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String sid=req.getParameter("sid");
        String sname=req.getParameter("sname");
        String password=req.getParameter("password");
        String sright=req.getParameter("sright");
        String sflag=req.getParameter("sflag");
        Student student=new Student(sid,sname,password,sright,sflag);
        System.out.println("要修改的学生信息："+student);
        StudentService service=new StudentServiceMysqlImpl();
        boolean flag=service.updateStudent(student);
        if(flag){
            System.out.println("修改成功");
        }else{
            System.out.println("修改失败");
        }
        resp.sendRedirect("/student/queryAllStu");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
